package xyf.p04.tree;

import commons.TreeNode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * ClassName: P0513_FindBottomLeftValue
 * Description:
 * Author: xyf
 * Date: 9/7/22 8:22 PM
 * Version: 1.0
 **/
public class P0513_FindBottomLeftValue
{
    public int findBottomLeftValue(TreeNode root)
    {
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        int ret = 0;
        while (queue.size() > 0)
        {
            TreeNode node = queue.poll();
            if (node.right != null)
            {
                queue.offer(node.right);
            }
            if (node.left != null)
            {
                queue.offer(node.left);
            }
            ret = node.val;
        }
        return ret;
    }
}
